- /* sdfdrand.cpp by K.Tsuru */
- // function ID 3005 DRADIX, BRADIX
- /********************************************************
- SDouble class for test
- Provides a random number with radix=rdx and exponent=exp.
- Default value exp = 0, radix = DRADIX.
- If size == 0 or size is greater than maxmum size it is
- adujusted to the maximum size.
- ******************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- #include <time.h>
- SDouble DRand(uint size, int exp, fType radix){
- SNumber::NumberType tp = (radix > DRADIX) ? SNumber::BIN_DEC : SNumber::REAL;
- fType rdx = (radix > DRADIX) ? BRADIX : DRADIX;
- uint max_sz = SNManager::SNMaxSize(tp);
- if(!size || (size > max_sz) ) size = max_sz;
-
- SDouble result(tp, size); // result = 0
- FigBlock a(size);
- time_t t;
- static uint seed = (uint)time(&t);
- srand(seed);
-
- uint j, first = (tp == SNumber::REAL) ? 1 : 0;
-
- if(first) a[0] = 0;
- for(j = first; j < size ; j++) a[j] = (fType)(rand() % rdx);
-
- fType f1 = first ? DRADIX/10 : BRADIX/8;
- while(a[first] < f1) a[first] = (fType)(rand() % rdx); //donot give 0.0001 1234.....
-
- seed = (uint)rand(); // set new seed for next call.
- result.SetFigBlock(a, result.PLUS, exp); // result.CheckArray(); done
- return result;
- }
sdfdrand.cpp : last modifiled at 2017/03/13 14:31:58(1,272 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).